#!/usr/bin/python
#-*- coding: utf-8 -*-

import sys,os,commands,stat,time
reload(sys)

auto_up = ['framework-storage']

base_dir = 'svn://manager.cloudsplus.com.cn/cloudsplus/trunk/framework/framework-storage'
dir = '/home/svn/cloudsplus/db'

svn_user = 'huangxuexin'
svn_passwd = 'huang!@#xuexin'
owner_id = 501
owner_group = 501

svn_up = '/usr/bin/svn up --username' + svn_user + '--password' + svn_passwd + '--no-auth-cache --non-interactive';

svn_hook = '/home/svn/cloudsplus/hooks/post-commit.tmpl'

print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
###auto update files
print 'Auto update dirs:'

for p in auto_up:
    print "\t", p
    commands.getstatusoutput(svn_up + base_dir + p)

###change owners
print 'Change owners:'

(rc1,rs1) = commands.getstatusoutput(svn_hook)
up_list = rs1.split("\n")
for f in up_list:
    file_name = f[4:]
    if f[0] != 'D':
        if os.path.exists(base_dir + file_name):
            os.chown(base_dir + file_name, owner_id, owner_group)
            if f[-3:] == '.py' or f[-3:] == '.sh' or f[-3:] == '.pl':
                os.chmod(base_dir + file_name,
                         stat.S_IREAD | stat.S_IWRITE | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH)
                print "\t", f[:3], file_name

print
